import importlib
import os

from flask_restx import Api

from settings import BaseConfig


api = Api(version="1.0", title="Flask API", description="A simple Flask API", doc="/docs")


def register_scheme(model_path: str):
    """
    注册命名空间、挂载序列化模型
    :param model_path:
    :return:
    """
    api_path = BaseConfig.API_DIR
    relative_part = os.path.relpath(model_path, api_path).replace(os.sep, '.')
    api_name = '.'.join(os.path.basename(relative_part).split('.')[:-1])
    ns_model = importlib.import_module('app.scheme.%s' % api_name)
    return ns_model.ns
